package qdu.edu.cn.liu.read;

import java.io.*;

/**
 * 从指定文件中读取需要查询的汉字词语
 */
public class ReadWordsFile {
    private BufferedReader bufferedReader;
    private FileInputStream fileInputStream;
    private InputStreamReader inputStreamReader;

    public ReadWordsFile(String filePath) {
        getInputStream(filePath);
    }

    private void getInputStream(String filePath) {
        try {
            fileInputStream = new FileInputStream(filePath);
            inputStreamReader = new InputStreamReader(fileInputStream);
            bufferedReader = new BufferedReader(inputStreamReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String getWords() {
        String str = null;
        try {
            if((str = bufferedReader.readLine()) == null) {
                bufferedReader.close();
                inputStreamReader.close();
                fileInputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
